export default {
    state: {
        // 服务器数据
        banner:[],
        recommend:[]
      },
      mutations: {
        changeBanner(state,banner){
          state.banner = banner
        },
        changeRecommend(state,recommend){
          state.recommend = recommend
        },
      },
      actions: {
        fetchHomeMultidataAction(context){
          // 1.返回Promise,给promise设置then
          // fetch("http://123.207.32.32:8000/home/multidata").then(res=>{
          //   res.json().then(data =>{
          //     console.log(data);
          //   })
          // })
          // 2.promise 链式调用
          // fetch("http://123.207.32.32:8000/home/multidata").then(res=>{
          //   return res.json()
          // }).then(data =>{
          //   console.log(data);
          // })
          // 3.await/async
          // const res = await fetch("http://123.207.32.32:8000/home/multidata")
          // const data = await res.json()
          // console.log(data);
          // context.commit('changeBanner',data.data.banner.list)
          // context.commit('changeRecommend',data.data.recommend.list)
    
          return new Promise(async (resolve,reject)=>{
            const res = await fetch("http://123.207.32.32:8000/home/multidata")
            const data = await res.json()
            context.commit('changeBanner',data.data.banner.list)
            context.commit('changeRecommend',data.data.recommend.list)
            resolve('aaaa')
          })
        }
      },
}